home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / amiga-magazin-pd / 03-95-2 / cybergraphics / cybershare / devdocs / examples / cybersavegio.c next >
C/C++ Source or Header  |  1995-03-09  |  5KB  |  194 lines

  1. /* cybergraphics saver - (C) Vision Factor Development 1994 31/12/94
  2.  
  3.    Saver for Photogenics
  4.    Photogenics © Almathera 1994, All Rights Reserved
  5.  
  6. REQUIRES: SAS C V6.50 or higher.
  7.  
  8. */
  9.  
  10.     #include <exec/types.h>
  11.     #include <clib/exec_protos.h>
  12.     #include <dos/dos.h>
  13.     #include <pragmas/exec_pragmas.h>
  14.     #include <cybergraphics/cybergraphics.h>
  15.     #include <intuition/intuition.h>
  16.     #include <pragmas/intuition_pragmas.h>
  17.     #include <pragmas/cybergraphics_pragmas.h>
  18.     #include <proto/exec.h>
  19.     #include <proto/intuition.h>
  20.     #include <proto/graphics.h>
  21.     #include <proto/cybergraphics.h>
  22.     #include "pgs_protos.h"
  23.     #include "pgs_pragmas.h"
  24.     #include "gio.h"
  25.  
  26. struct    TagItem CModeTags[]=
  27.     {
  28.      CYBRMREQ_Screen,0,
  29.      CYBRMREQ_MinDepth,15,
  30.      CYBRMREQ_MaxDepth,32,
  31.      CYBRMREQ_WinTitle,(ULONG)"Select CyBERgraphics ScreenMode",
  32.      CYBRMREQ_OKText,(ULONG)"OK",
  33.      CYBRMREQ_CancelText,(ULONG)"Cancel",
  34.      TAG_DONE
  35.     };
  36.  
  37.  
  38. struct Library *CyberGfxBase;
  39.  
  40. /* prototypes */
  41. __asm ULONG __saveds GioInfo(void);
  42. __asm ULONG __saveds GioExamine(register __a0 struct GIOData *giodata);
  43. __asm ULONG __saveds GioRead(register __a0 struct GIOData *giodata);
  44. __asm ULONG __saveds GioWrite(register __a0 struct GIOData *giodata);
  45. /* end of prototypes */
  46.  
  47.  
  48. __asm ULONG __saveds GioInfo(void)
  49. {
  50.     return(GIOF_SAVER24);
  51. }
  52.  
  53. __asm ULONG __saveds GioExamine(register __a0 struct GIOData *giodata)
  54. {
  55.  return(0L);
  56. }
  57.  
  58. #define DOSBase giodata->DOSBase
  59. #define PgsBase giodata->PgsBase
  60. #define IntuitionBase giodata->IntuitionBase
  61.  
  62. __asm ULONG __saveds GioRead(register __a0 struct GIOData *giodata)
  63. {
  64.  return(0L);
  65. }
  66.  
  67. __asm ULONG __saveds GioWrite(register __a0 struct GIOData *giodata)
  68. {
  69.     if (giodata->Depth == 24)
  70.     {
  71.      int ScrWidth,ScrHeight,OffX=0,OffY=0,DispWidth,DispHeight;
  72.  
  73.     if(CyberGfxBase=OpenLibrary("cybergraphics.library",40))
  74.     {
  75.      struct Screen *Scr;
  76.      int Width,Height;
  77.      ULONG    ModeID;
  78.  
  79.      CModeTags[0].ti_Data=(ULONG)giodata->PgsScreen;
  80.      ModeID=CModeRequestTagList(0L,CModeTags);
  81.  
  82.      Width = giodata->Width; Height = giodata->Height;
  83.  
  84.      if(Scr=(struct Screen *)OpenScreenTags(0L,SA_DisplayID,ModeID,
  85.                            SA_AutoScroll,1,
  86.                            SA_Overscan,1,
  87.                            SA_Depth,8,
  88.                            TAG_DONE))
  89.      {
  90.       struct Window *Wnd;
  91.       ScrWidth=Scr->Width; ScrHeight=Scr->Height;
  92.       if(Wnd=(struct Window *)OpenWindowTags(0L,WA_Activate,1,
  93.                             WA_CustomScreen,Scr,
  94.                             WA_Width,Scr->Width,
  95.                             WA_Height,Scr->Height,
  96.                             WA_Borderless,1,
  97.                             WA_Backdrop,1,
  98.                             WA_IDCMP,IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS,
  99.                             TAG_DONE))
  100.       {
  101.        struct IntuiMessage *imsg;
  102.        BOOL end=FALSE,UpdateDis=TRUE;
  103.  
  104.  
  105.         DispWidth=ScrWidth; if(Width < ScrWidth) DispWidth = Width;
  106.        DispHeight=ScrHeight; if(Height < ScrHeight) DispHeight = Height;
  107.  
  108.        while(!end)
  109.        {
  110.         if(UpdateDis)
  111.         {
  112.          int y;
  113.          UBYTE *peeker;
  114.          for(y=0;y<DispHeight;y++)
  115.          {
  116.           peeker=GetLine(giodata,y+OffY);
  117.           WritePixelArray(peeker,OffX,0,DispWidth*4,&Scr->RastPort,0,y,DispWidth,1,RECTFMT_RGB);
  118.           ReleaseLine(giodata,y+OffY);
  119.          };
  120.         UpdateDis=FALSE;
  121.        }
  122.  
  123.        WaitPort(Wnd->UserPort);
  124.  
  125.        while(imsg=(struct IntuiMessage *)GetMsg(Wnd->UserPort))
  126.        {
  127.         ULONG IClass=imsg->Class;
  128.         UWORD IQual=imsg->Qualifier;
  129.         UWORD ICode=imsg->Code;
  130.         UWORD StepX,StepY;
  131.      
  132.         switch(IClass)
  133.         {
  134.          case MOUSEBUTTONS:
  135.         end=TRUE;
  136.         break;
  137.          case RAWKEY:
  138.         if(IQual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  139.         { StepX=StepY=1; }
  140.         else
  141.         { StepX=DispWidth; StepY=DispHeight; }
  142.  
  143.         switch(ICode)
  144.         {
  145.          case CURSORUP: // CSUP
  146.             if(OffY!=0)
  147.             { OffY-=StepY; if(OffY < 0) OffY=0; UpdateDis=TRUE; }
  148.             break;
  149.          case CURSORDOWN: // CSDN
  150.             if(Height > DispHeight)
  151.             {
  152.              OffY+=StepY;
  153.              if(OffY > Height-DispHeight)
  154.              { OffY=Height-DispHeight; if(OffY < 0) OffY=0;    }
  155.             UpdateDis=TRUE;
  156.             };
  157.             break;
  158.          case CURSORRIGHT: // CSRT
  159.             if(Width > DispWidth)
  160.             {
  161.              OffX+=StepX;
  162.              if(OffX > Width-DispWidth)
  163.              { OffX=Width-DispWidth; if(OffX < 0) OffX=0; };
  164.              UpdateDis=TRUE;
  165.             };
  166.             break;
  167.          case CURSORLEFT: // CSLT
  168.             if(OffX!=0)
  169.             { OffX-=StepX; if(OffX < 0) OffX=0; UpdateDis=TRUE; };
  170.             break;
  171.             }
  172.             break;
  173.       } // end of switch
  174.      } // end of while 
  175.         } // end of while(!end)
  176.        CloseWindow(Wnd);
  177.        } // end of OpenWindow
  178.        else giodata->Error = LOAD_RAMERR;
  179.        CloseScreen(Scr);
  180.       } // end of OpenScreen
  181.       else giodata->Error = LOAD_RAMERR;
  182.       CloseLibrary(CyberGfxBase);
  183.      }
  184.      else giodata->Error = LOAD_SYSERR;
  185.     }
  186.     else
  187.     {
  188.      giodata->Error = LOAD_WRONGTYPE;
  189.     }
  190.  return(0L);
  191. }
  192.  
  193.     
  194.